package com.ytjj.qmyx.admin.service.impl;

import com.ytjj.qmyx.admin.mapper.AdminMapper;
import com.ytjj.qmyx.admin.model.Admin;
import com.ytjj.qmyx.admin.model.AdminExample;
import com.ytjj.qmyx.admin.service.MemberService;
import com.ytjj.qmyx.admin.utils.UserUtil;
import com.ytjj.qmyx.mall.mapper.BankerMapper;
import com.ytjj.qmyx.mall.model.Banker;
import com.ytjj.qmyx.mall.model.BankerExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class MemberServiceImpl implements MemberService {

    @Resource
    private AdminMapper adminMapper;

    @Resource
    private BankerMapper bankerMapper;

    @Override
    public Admin getAdmin() {
        String principal = UserUtil.getPrincipal();
        AdminExample adminExample = new AdminExample();
        adminExample.createCriteria().andEmailEqualTo(principal);
        List<Admin> admins = adminMapper.selectByExample(adminExample);
        return admins.get(0);
    }

    @Override
    public Banker getBanker() {
        String principal = UserUtil.getPrincipal();
        BankerExample bankerExample = new BankerExample();
        bankerExample.createCriteria().andTelEqualTo(principal);
        List<Banker> bankers = bankerMapper.selectByExample(bankerExample);
        return bankers.get(0);
    }
}
